package com.ebo.common.smart.parser;

import cn.hutool.core.lang.RegexPool;
import cn.hutool.core.util.ReUtil;
import cn.hutool.core.util.StrUtil;
import com.ebo.common.smart.TextHolder;
import com.ebo.common.smart.domain.UserInfo;

import java.util.List;

/**
 * 电话解析器
 */
public class ZipCodeParser {


    public void parse(UserInfo userInfo, List<String> textList, TextHolder textHolder) {
        for (int i = 0; i < textList.size(); i++) {
            String text = textList.get(i);
            String zipCode = matchZipCode(text);

            if (!StrUtil.isEmpty(zipCode) ) {
                textList.set(i, textList.get(i).replace(zipCode, ""));
//                userInfo.setMobile(zipCode);
                textHolder.removeText(zipCode);
                text = text.replace(zipCode,"");
            }
        }
    }

    /**
     * 匹配邮政编码
     *
     * @param text
     * @return
     */
    public String matchZipCode(String text) {
        String zipCode = ReUtil.getGroup0("^(0[1-7]|1[0-356]|2[0-7]|3[0-6]|4[0-7]|5[0-7]|6[0-7]|7[0-5]|8[0-9]|9[0-8])\\d{4}|99907[78]$|000000", text);
        if (StrUtil.isNotEmpty(zipCode)) {
            return zipCode;
        }

//        mobile = ReUtil.getGroup0(RegexPool.TEL, text);
//        if (StrUtil.isNotEmpty(mobile)) {
//            return mobile;
//        }

//        mobile = ReUtil.getGroup0(RegexPool.TEL_400_800, text);
//        if (StrUtil.isNotEmpty(mobile)) {
//            return mobile;
//        }
//        mobile = ReUtil.getGroup0(RegexPool.MOBILE_HK, text);
//        if (StrUtil.isNotEmpty(mobile)) {
//            return mobile;
//        }
//        mobile = ReUtil.getGroup0(RegexPool.MOBILE_TW, text);
//        if (StrUtil.isNotEmpty(mobile)) {
//            return mobile;
//        }
        return ReUtil.getGroup0(RegexPool.MOBILE_MO, text);
    }


}

